<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .train2 {
        margin: 300px auto;
        width: 300px;
        height: 100px;
        display: flex;
        border: 0 solid;
        justify-content: space-between;
        align-items: center;
        background-color: rgb(226, 192, 255);
    }

    .train2 input {
        width: 50px;
        background-color: white;
    }

    .train2 span {
        width: 50px;
        height: 24px;
        background-color: white;
        border: 2px solid black;
        text-align: center;
        line-height: 24px;
    }
</style>

<body>
    <div class="train2">
        <input id="num1" type="number">
        <select id="opt">
            <option>+</option>
            <option>-</option>
            <option>*</option>
            <option>/</option>
        </select>
        <input id="num2" type="number">
        <span onclick="count()">=</span>
        <span id="res"></span>
    </div>
    <script>
        function count() {
            let num1 = document.getElementById("num1").value;
            let opt = document.getElementById("opt").value;
            let num2 = document.getElementById("num2").value;
            let res = eval(num1 + opt + num2);//eval会将括号内字符串当js代码运行
            document.getElementById("res").innerText = res;
        }
    </script>
</body>

</html>